/*

  Listing

  Copyright © 2011 F.Hroch (hroch@physics.muni.cz)

  This file is part of Munipack.

  Munipack is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  Munipack is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with Munipack.  If not, see <http://www.gnu.org/licenses/>.


*/

// listing of all usefull info from FITS

// light curve, absolute, relative  magnitudes, intensity, sky, jd, 
//              airmass, helcor ...?
// all calibrated !


#include "munipack.h"
#include <wx/wx.h>
#include <wx/tokenzr.h>


bool Munipack::listing(MuniCmdLineParser& cmd)
{
  MuniProcess *action = new MuniProcess(&pipe,"list");
  //MuniProcess *action = new MuniProcess(&pipe,"cat");
  pipe.push(action);

  wxString a;

  if( cmd.Found("c",&a) )
    action << ("COLUMN = '" + a + "'");

  if( cmd.Found("mag") )
    action << wxString("MAG = 1");

  if( cmd.Found("full") )
    action << wxString("FULL_LISTING = 1");

  if( cmd.Found("pos") )
    action << wxString("POSITION_LISTING = 1");

  /*
  if( cmd.Found("relative",&a) )
    action << wxString("RELATIVE = 1");
  */

  if( cmd.Found("geo",&a) )
    action << ("GEOGRAPHICAL = " + a);

  if( cmd.Found("equ",&a) )
    action << ("EQUATORIAL = " + a);

  if( cmd.Found("ele",&a) )
    action << ("LC_ELEMENTS = " + a);

  if( cmd.Found("tol",&a) )
    action << ("TOL = " + a);

  if( cmd.Found("k",&a) ) {

    action << wxString("HEADER = 1");

    wxStringTokenizer tokenizer(a, ",");
    while ( tokenizer.HasMoreTokens() )
      action << ("KEYWORD = '" + tokenizer.GetNextToken() + "'");
  }

  for(size_t i = 1; i < cmd.GetParamCount(); i++) {

    wxString l = cmd.GetParam(i);
    long d;

    if( l.Find(',') != wxNOT_FOUND )
      action << ("RECT = " + l + ",0,0");

    else if( l.ToLong(&d) )
      action << ("INDEX = " + l);

    else
      action << ("FILE = '" + l + "'");
  }


  pipe.Start();

  return true;
}
